package com.mygdx.screen;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.*;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.mygdx.contact.CommonContact;
import com.mygdx.game.MyGdxGame;
import com.mygdx.screen.listener.ButtonQuitListener;

/**
 * @Title: CommonScreen
 * @Author RuoLi
 * @Package com.mygdx.screen
 * @Date 2023/12/19 23:03
 * @description: 通用舞台
 */
public class CommonActor extends Actor{
    private Stage stage;
    private TextButton textButton;

    private TextButton.TextButtonStyle textButtonStyle;
    public CommonActor() {
        stage = new Stage();
        textButtonStyle = new TextButton.TextButtonStyle();
        textButtonStyle.font = MyGdxGame.font;//字体默认为MyGdx设置字体
        stage=new Stage();
        Gdx.input.setInputProcessor(stage);
        setSettingButton();
        setQuitButton();

    }

    public void createTextButton(float x, float y, String text) {
        textButton = new TextButton(text, textButtonStyle);
        textButton.setPosition(x, y);
    }

    public Actor addActorTextButton() {
        return this.textButton;
    }

    public TextButton.TextButtonStyle getTextButtonStyle() {
        return textButtonStyle;
    }

    //设置按钮
    private void setSettingButton(){
        textButton = new TextButton(CommonContact.SETTING.name(), textButtonStyle);
        textButton.setPosition(10, Gdx.graphics.getHeight() - 40);
        stage.addActor(textButton);
    }

    //退出按钮
    private void setQuitButton(){
        textButton = new TextButton(CommonContact.EXIT.name(), textButtonStyle);
        textButton.setPosition(Gdx.graphics.getWidth() - 80, Gdx.graphics.getHeight() - 40);
        stage.addActor(textButton);
        textButton.addListener(new ButtonQuitListener());
    }

    public void render(){
        stage.act();
        stage.draw();
    }
}
